package managesystem;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class changeEmailServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) {
		HttpSession session = req.getSession();
		Student currStud = (Student) session.getAttribute("currStud");
		
		String email = req.getParameter("emailadress");
		if(email.equals("") || !email.contains("@") || !email.contains(".")) {
			String error = "Please fill in a correct emailadress.";
			session.setAttribute("error",error);
		}
		else {
			currStud.setEmail(email);
			StudentManager.add(currStud);
			session.setAttribute("currStud",currStud);
		}
		try {
			resp.sendRedirect("/index.jsp?id=ucp");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
